package cn.edu.nuc.crm.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.crm.dao.SysfunctionMapper;
import cn.edu.nuc.crm.dto.PageInfo;
import cn.edu.nuc.crm.entity.Sysfunction;
import cn.edu.nuc.crm.service.interfaces.SysfunctionService;


@Service
public class SysfunctionServiceImpl implements SysfunctionService {
	@Autowired
	private SysfunctionMapper sysfunctionMapper;
	
	public List<Sysfunction> select1(int roleid) {
		List<Sysfunction> list= sysfunctionMapper.select1(roleid);
		return list;
	}
	
	@Override
	public List<Sysfunction> sysfunctionlist() {
		List<Sysfunction> sysfunctionlist = new ArrayList<Sysfunction>();
		sysfunctionlist = sysfunctionMapper.sysfunctionlist();
		return sysfunctionlist;
	}
	
	public PageInfo sysfunction(int current) {
		PageInfo pi = new PageInfo(current);
		int count = sysfunctionMapper.count();
		pi.setCount(count);
		//System.out.println( pi.getStart() + "======"+ pi.getOffset() );
		List<Sysfunction> findByid=sysfunctionMapper.findByid(pi.getStart(), pi.getOffset());
		pi.setList(findByid);
		System.out.println("总的记录数:"+count+"--"+pi);
		return pi;
	}
	/**
	 * 添加addSysfunction
	 */
	@Override
	public int insert(Sysfunction record) {
		
		int result =sysfunctionMapper.insert(record);
		return result;
	
	}
	/**
	 * 查询功能列表
	 */
	@Override
	public List<Sysfunction> selectByName(String funname) {
		List<Sysfunction> name = sysfunctionMapper.selectByName(funname);
		return name;
	}
	//删除功能
	@Override
	public int deleteByPrimaryKey(Integer funid) {
		int result=sysfunctionMapper.deleteByPrimaryKey(funid);
		return result;
	}

	@Override
	public Sysfunction selectByPrimaryKey(Integer funid) {
		
		Sysfunction sys=sysfunctionMapper.selectByPrimaryKey(funid);
		return sys;
		
	}

	@Override
	public int updateByPrimaryKeySelective(Sysfunction record) {
		
		int result=sysfunctionMapper.updateByPrimaryKey(record);
		if(result>0){
			return result;
		}else{
			throw new RuntimeException("修改失败");
		}
			
	}
	@Override
	public List<Sysfunction> select() {
		List<Sysfunction> list=sysfunctionMapper.select();
		return list;
	}

	public List<Sysfunction> select3() {
		List<Sysfunction> list=sysfunctionMapper.select3();
		return list;
	}
	public List<Sysfunction> select2() {
		List<Sysfunction> list=sysfunctionMapper.select2();
		return list;
	}
}
